package medium;

import java.util.HashSet;
import java.util.Set;

/**
 * 创建时间：2025-05-26 19:21
 */
public class 最长连续序列_128 {
    public int longestConsecutive(int[] nums) {
        Set<Integer> set = new HashSet<>();
        for (int num : nums) {
            set.add(num);
        }
        int max = 0;
        for (Integer s : set) {
            if (set.contains(s - 1)) {
                continue;
            }
            int y = s + 1;
            while (set.contains(y)) {
                y++;
            }
            max = Math.max(max, y-s);
        }
        return max;
    }
}
